<?php
/**
 * Nguoi tao: Phuongtt
 * Ngay tao: 27/12/2012
 * Y nghia: Cap nhat xu ly bai giang
 */	
class mtl_trainingController extends  Zend_Controller_Action {
	public function auth(){
        $url = Efy_Init_Config::_getCurrentHttpAndHost();
        if (!Efy_Init_Session::Checkpermission($_SESSION['staff_id'])){
            $url = $url .'public/error/index/';
            $this->_redirect($url);
        }
    }
    public function authsynthesis(){
        $url = Efy_Init_Config::_getCurrentHttpAndHost();
        if (($_SESSION['STAFF_PERMISSTION'] != 'ADMIN_SYSTEM') && ($_SESSION['STAFF_PERMISSTION'] != 'ADMIN_OWNER')){
            $url = $url .'public/error/index/';
            $this->_redirect($url);
        }
    }
	public function init(){
		//Check login
		$Efy_Init_Config = new Efy_Init_Config();
		if('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] != $Efy_Init_Config->_setUserLoginUrl()){
			$owc = $Efy_Init_Config->_setWebSitePath();
			$owc = str_replace("/", "", $owc);				
			//Kiem tra user da dang nhap phan mem hay chua				
			if(!isset($_SESSION['staff_id']) || is_null($_SESSION['staff_id'])){				
				//Kiem tra thong tin NSD?>
				<script type="text/javascript">
					 UrlRes = '<?php echo $Efy_Init_Config->_setUserLoginUrl() ?>';					 
					 window.location = UrlRes; 					
				</script><?php	
			}
			else{
				if (!isset($_SESSION['INFORMATION_STAFF_LOGIN_MTL'])) {
					$staffName = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
					$positionCode = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code');
					$unitId = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'unit_id');
					$unitName = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_unit'],$unitId,'name');
					$baseUrl = $Efy_Init_Config->_setLibUrlPath();
					$_SESSION['INFORMATION_STAFF_LOGIN_MTL'] = efy_library::_getInformationStaffLoginMtl($staffName,$positionCode,$unitName,$baseUrl);
				}
				//Check tree
				$objefy = new Efy_Library();
				$objefy->checkdatatree();
			}
		}
		//	
		Zend_Loader::loadClass('mtl_modTraining');
		Zend_Loader::loadClass('listxml_modTree');
		Zend_Loader::loadClass('Zend_Json');	    
		//Load cau hinh thu muc trong file config.ini
        $tempDirApp = Zend_Registry::get('conDirApp');
		$this->_dirApp = $tempDirApp->toArray();
		$this->view->dirApp = $tempDirApp->toArray();
		//Lay duong dan thu muc goc (path directory root)
		$this->view->baseUrl = $this->_request->getBaseUrl() . "/public/";
		if (!$this->_request->isXmlHttpRequest()){
			//Cau hinh cho Zend_layout
			Zend_Layout::startMvc(array(
				    'layoutPath' => $this->_dirApp['layout'],
				    'layout' => 'index'			    
				    ));	
			//Load cac thanh phan cau vao trang layout (index.phtml)
			$response = $this->getResponse();
			//Ky tu dac biet phan tach giua cac phan tu
			$this->view->delimitor 	= "!~~!";	
			//Load cau hinh thu muc trong file config.ini de lay ca hang so dung chung
	        $tempConstPublic = Zend_Registry::get('ConstPublic');
			$this->_ConstPublic = $tempConstPublic->toArray();	
			//Lay cac hang so su dung trong JS public
			$objConfig = new Efy_Init_Config();
			$objConst = new Efy_Init_Const();
			$this->view->JSPublicConst = $objConfig->_setJavaScriptPublicVariable();	
			// var_dump($objConfig->_setJavaScriptPublicVariable());	
			$this->view->UrlAjax = $objConfig->_setUrlAjax();
			$arrConst = $objConst->_setProjectPublicConst();
			$this->view->arrConst = $arrConst;
			// Load tat ca cac file Js va Css
			$this->view->LoadAllFileJsCss = Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','mtl/training.js,jquery.maskedinput-1.3.js',',','js')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-style','jquery.multiselect.css,jquery.multiselect.filter.css',',','css')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-style','mtl/training.css',',','css')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','jquery.multiselect.js,jquery.multiselect.filter.js',',','js')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','mtl/training.js',',','js');
			//Dinh nghia current modul code
			$this->view->currentModulCode = "TRAINING";
			$this->view->currentModulCodeForLeft = $this->_request->getParam('action');
			$response->insert('header', $this->view->renderLayout('header.phtml','./application/views/scripts/'));    	//Hien thi header 
			$response->insert('menu', $this->view->renderLayout('menu.phtml','./application/views/scripts/'));    		//Hien thi header 		
	        $response->insert('footer', $this->view->renderLayout('footer.phtml','./application/views/scripts/')); 			
		}else{			
			$result = array();
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('','efy-js'
				,'mtl/training.js,jquery.multiselect.filter.js,jquery.multiselect.js,jquery.maskedinput-1.3.js'
				,','
				,'js'
				,$result);
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray(''
					,'efy-style'
					,'mtl/training.css,jquery.multiselect.css'
					,','
					,'css'
					,$result);
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('','efy-js','tiny_mce/tiny_mce.js',',','js',$result);			
			$this->view->arrJsCss = Zend_Json::encode($result);	
			$baseurl=$this->_request->getbaseurl();			 
		}
	}	
	/**
	 * @author: Phuongtt
	 * @see: 27/12/2012
	 * @todo: Hien thi danh sach bai giang
	 * Enter description here ...
	 */
	public function indexAction(){
		$arrWards = array();	
		$objFunction = New Efy_Function_RecordFunctions();
		$this->view->titleBody = "DANH SÁCH TÀI LIỆU";
		$this->view->currentModulCode = "TRAINING";
		$status = $this->_request->getParam('TD06');
		$this->view->arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');						
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->status = $status;
		$this->view->iNumberRecordPerPage = 12;		
	}
	
	/**
	 * @author: Phuongtt
	 * @see: 27/12/2012
	 * @todo: Hien thi danh sach bai giang
	 * Enter description here ...
	 */
	public function addAction(){
		$arrWards = array();		
		$objFunction = New Efy_Function_RecordFunctions();						
		$this->view->arrClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_SACH');
		$this->view->arrTacgia = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TAC_GIA');
		//Lay danh muc nhom nguoi dung
		$arrGroupUser = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_NHOM_NGUOI_DUNG');
		$arrGroupUserView = array();
		$arrGroupUserDownload = array();
		foreach ($arrGroupUser as $key => $data) {
			array_push($arrGroupUserView,array('C_CODE'=>'VIEW_'.$data['C_CODE'],'C_NAME'=>$data['C_NAME']));
			array_push($arrGroupUserDownload,array('C_CODE'=>'DOWN_'.$data['C_CODE'],'C_NAME'=>$data['C_NAME']));
		}
		$this->view->arrGroupUserView = $arrGroupUserView;
		$this->view->arrGroupUserDownload = $arrGroupUserDownload;
        $attachFileThumbnail = $objFunction->FormAttachFileThumbnail(array(),'TRAINING_DOC');
        $this->view->attachFileThumbnail = $attachFileThumbnail;
		$this->view->attachFile = $objFunction->FormAttachDocument('','TRAINING_DOC');
		$this->view->attachFileFlash = $objFunction->FormAttachFlash('','TRAINING_DOC');
		$reques = $this->_request->getParams('');
		//Lay danh sach lanh dao duyet bai giang
		$arrApproveStaff = array();
		foreach ($_SESSION['arr_all_staff'] as $key => $data) {
			if($data['position_group_code'] == 'LANH_DAO_KHOI_TRUONG'){
				array_push($arrApproveStaff, array('id'=>$data['id'],'name'=>$data['position_code'].' - '.$data['name'],'position_code'=>$data['position_code'],'position_name'=>$data['position_name']));
			}			
		}
		
		$this->view->arrApproveStaff = $arrApproveStaff;
		$this->view->td03id = isset($reques['td03'])?$reques['td03']:'';
		$this->view->td03name = isset($reques['td03name'])?$reques['td03name']:'';
	}
	public function trainingindexdataAction(){
		//Tao doi tuong
		$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();		
		$data = $this->_request->getParams('');		
		//Mảng lưu danh sách
		$arrResult = array();
		//Mảng lưu tiêu chí tìm kiếm
		$dataSearch = $this->_request->getParam('td18');
		$dataSearch = Efy_Publib_Library::_Replace_VietNamese($dataSearch);
		$dataSearch = strtolower($dataSearch);
		$td03 = $this->_request->getParam('td03');
		// Lay duong dan:
		$breadcrumbs = $objFunction->genbreadcrumbs($td03);
		
		$arrParameter = array(	
			'td03'                 => $td03,
			'td18'                 => $dataSearch,
			'td06s'                => $this->_request->getParam('TD06'),
			'td04'                 => $_SESSION['staff_id'],
			'iCurrentPage'         => $this->_request->getParam('hdn_current_page'),
			'iNumberRecordPerPage' => $this->_request->getParam('hdn_record_number_page')				
		);				
		$arrResult = $objModel->mTLSPRun('mTL_TraingGetAll',$arrParameter, 1,0);
		for ($i=0; $i < sizeof($arrResult); $i++) { 	
			if($arrResult[$i]['C_STATUS'] == 'DA_CHO_Y_KIEN' && $arrResult[$i]['ORDER_STATUS'] == '2'){
				$arrResult[$i]['TD06'] .= '<p style="margin:-25px 0 0 85px;"><img src="../../../public/images/da phan hoi.gif">';
			}		
			$arrResult[$i]['TD23'] = ($arrResult[$i]['TD23'] != null)?$arrResult[$i]['TD23']:'';
			$arrResult[$i]['TD19'] = ($arrResult[$i]['TD19'] != null)?str_replace('!@!', ', ', $arrResult[$i]['TD19']):'';

			$fileNameThumb = $arrResult[$i]['C_FILENAME_THUMB'];
			if(is_null($fileNameThumb) || $fileNameThumb ==''){
				$arrResult[$i]['C_FILENAME_THUMB'] = $objconfig->_setAttachFileUrlPath().'default/default.jpg';
			}else{
				$arrFilename = explode('!~!',$fileNameThumb);
				$file_id   = explode("_", $arrFilename[0]);
	        	$srcThumBnail = $objconfig->_setAttachFileUrlPath() . $file_id[0] . "/" . $file_id[1] . "/" . $file_id[2] . "/" . $fileNameThumb;
	        	$pathFileExist = '..' . str_replace("/","\\",$srcThumBnail);
				if(file_exists($pathFileExist)) 
					$arrResult[$i]['C_FILENAME_THUMB'] = $srcThumBnail;
				else
					$arrResult[$i]['C_FILENAME_THUMB'] = $objconfig->_setAttachFileUrlPath().'default/default.jpg';
			}

		}
        //var_dump($arrResult); exit;

		echo Zend_Json::encode(array('breadcrumbs'=>$breadcrumbs,'arrResult'=>$arrResult));
		$this->getHelper('viewRenderer')->setNoRender();  		
	}
	public function getChildNode($idNode,$arrTreeGetAll){
		$arrOutput = array();
		foreach ($arrTreeGetAll as $key => $value) {
			if($value['FK_OBJECT'] == $idNode){
				array_push($arrOutput, array('attr'=>array(
												'id'=>$value['PK_OBJECT']
												,'rel'=>'folder'
											),
											'data'=>$value['TR04'],
											'state'=>'closed'
				));
			}
		}
		return $arrOutput;
	}
	public function loadtreeAction(){
		$objTree	= new Listxml_modTree();
		$arrTree = '';
		$sType = $this->_request->getParam('sType',null);
		$searchNodes = $this->_request->getParam('searchNodes',null);
		$arrParameter = array(
			'status'=>'HOAT_DONG'
			,'txtFullTextSearch'=>''
			,'type'=>$sType
			,'sOwner_code'=>$this->_request->getParam('ownerCode')
		);
		if ($sType == 'TRAINING'){
			if(!isset($_SESSION['TREE_TRAINING'])){
				$objTree	= new Listxml_modTree();
				$_SESSION['TREE_TRAINING'] = $objTree->mTL_TreeGetAll($arrParameter);
			}
			$arrTreeGetAll = $_SESSION['TREE_TRAINING'];
		}
		else if ($sType == 'LEARNING'){
			if(!isset($_SESSION['TREE_LEARNING'])){
				$objTree	= new Listxml_modTree();
				$_SESSION['TREE_LEARNING'] = $objTree->mTL_TreeGetAll($arrParameter);
			}
			$arrTreeGetAll = $_SESSION['TREE_LEARNING'];
		}
		$idNode = $this->_request->getParam('id',null);
		$arrTree = $this->getChildNode($idNode,$arrTreeGetAll);
		if ($searchNodes != '')
			$arrTree = $arrTreeGetAll;
		echo json_encode($arrTree);
		$this->getHelper('viewRenderer')->setNoRender();  
	}
	public function ajaxstaffAction(){}
	public function ajaxstaffdownAction(){}
	public function savetrainingindexAction(){
		$objconfig = new Efy_Init_Config();
		$objModel = new mtl_modTraining();		
		$objFunction = new Efy_Function_RecordFunctions();
		$arrClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_SACH');				
		$data = $this->_request->getParams('');
        //var_dump($data); exit;
		$sStaffName = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');

		$td06 = $data['td06'];
		$status = '';
		$idLeader = '';
		$nameLeader = '';
		$approveDate = '';		
		switch ($td06) {
			case 'cl':
				$status = 'CHUYEN_LUU';
				$idLeader = $data['td10'];
				$nameLeader = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$idLeader,'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$idLeader,'name');
				$approveDate = $data['td12'];
				break;
			default:
				# code...
				break;
		}
		if($data['listStaff'] != ''){
			$arrPkStaff = explode(",", $data['listStaff']);
			$strStaff = Efy_Publib_Library::_getStaff($_SESSION['arr_all_staff'], $arrPkStaff);
		}else $strStaff = '';
		$link_db_user  = $objconfig->_setDbLinkUser();
		$dataSearch = $data['td02'].','.$data['td08'].' - '.$data['td09'].','.$data['listClassName'].','.$data['td17'];
		$dataSearch .= ','.$data['hdnpath'];
		$dataSearch = Efy_Publib_Library::_Replace_VietNamese($dataSearch);
		$dataSearch = strtolower($dataSearch);
		//Lay nhom nguoi
		$listGroupDownCode = $data['listGroupDownCode'];
		$listGroupDownName = $data['listGroupDownName'];
		$listGroupViewCode = $data['listGroupViewCode'];
		$listGroupViewName = $data['listGroupViewName'];
        //Upload hinh dai dien
        $sUrlFileAttach = $objconfig->_setAttachFileUrlPath();
        $urlAttachFileThumb = '';
        if($data['urlattachfileThumbnail'] !=''){
            $fileNameAttachThumb = $objFunction->_uploadFileAttachList($data['urlattachfileThumbnail'],$sUrlFileAttach);
            $urlAttachFileThumb = $fileNameAttachThumb;
        }
       	$chk_attach = '';
        if($data['chk_attach'] !=''){
            $chk_attach = $objFunction->_uploadFileAttachList($data['chk_attach'],$sUrlFileAttach);
        }
        $chk_attach_flash = '';
        if($data['chk_attach_flash'] !=''){
            $chk_attach_flash = $objFunction->_uploadFileAttachList($data['chk_attach_flash'],$sUrlFileAttach);
        }
        $td02= htmlspecialchars($data['td02']);
		//echo $td02; die();
		$arrParameter = array(
			'td01'                 => isset($data['td01'])?$data['td01']:'',
			'td02'                 => isset($td02)?$td02:'',
			'td03'                 => isset($data['selectValueTreeImg'])?$data['selectValueTreeImg']:'',
			'td04'                 => $_SESSION['staff_id'],
			'td05'         		   => $sStaffName,
			'td20'				   => isset($data['listClassCode'])?$data['listClassCode']:'',				
			'td19'				   => isset($data['listClassName'])?$data['listClassName']:'',
			'td08'				   => isset($data['td08'])?$data['td08']:'',
			'td09'				   => isset($data['td09'])?$data['td09']:'',
			'td06'				   => $status,
			'td13'				   => isset($data['td13'])?$data['td13']:'',
			'td14'				   => isset($data['td14'])?$data['td14']:'',
			'td15'				   => isset($data['td15'])?$data['td15']:'',
			'td15_down'			   => isset($data['td15_down'])?$data['td15_down']:'',
			'td10'				   => $idLeader,
			'td11'				   => $nameLeader,
			'td12'				   => $approveDate,
			'td21'				   => isset($data['listStaff'])?$data['listStaff']:'',
			'listStaffdown'		   => isset($data['listStaffdown'])?$data['listStaffdown']:'',
			'tac_gia'			   => isset($data['listAuthor']) ? $data['listAuthor']:'',
			'listGroupViewCode'	   => $listGroupViewCode,
			'listGroupDownCode'	   => $listGroupDownCode,
			'TDSF03s'			   => $strStaff,  //Danh sach chuc vu - ten cua can bo 	
			'td17'				   => isset($data['td17'])?$data['td17']:'',
			'td16'				   => isset($data['td16'])?$data['td16']:'',
			'td07'				   => $_SESSION['OWNER_CODE'],
			'td18'				   => $dataSearch,
			'link_db_user'		   => $link_db_user,
            'filenameThumb'        => $urlAttachFileThumb,
            'chk_attach' 			=> $chk_attach,
            'chk_attach_flash'      => $chk_attach_flash,
		);
        //var_dump($arrParameter); exit;
		$arrResult = $objModel->mTLSPRun('mTL_TraingUpdate',$arrParameter, 0,0);
		//Upload file đính kèm
		$recordId = $arrResult['NEW_ID'];				
		//Xoa file
		if($data['hdn_chk_attach'] != $data['chk_attach'] && $data['hdn_chk_attach'] !=''){
			$file = '..'.$data['hdn_chk_attach'];
			echo 11;
			if(file_exists($file))
				unlink($file);	
		}
		if($data['hdn_chk_attach_flash'] != $data['chk_attach_flash'] && $data['hdn_chk_attach_flash'] !=''){
			$file = '..'.$data['hdn_chk_attach_flash'];
			if(file_exists($file))
				unlink($file);	
		}
		exit;
	}

	private function getpathfile($urlPath, $fileName) {
		$href ='';
		if(!(is_null($fileName) || $fileName =='')){
			$arrFilename = explode('!~!',$fileName);
			$file_id   = explode("_", $arrFilename[0]);
        	$href = $urlPath . $file_id[0] . "/" . $file_id[1] . "/" . $file_id[2] . "/" . $fileName;
        	$pathFileExist = '..' . str_replace("/","\\",$href);
        	if(!file_exists($pathFileExist)) $href ='';
		}
		return $href;
	}
	public function getsingleAction(){
		$objModel = new mtl_modTraining();		
		$objFunction = new Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();
		$data = $this->_request->getParams('');						
		$arrParameter = array(	
			'td01' => isset($data['td01'])?$data['td01']:''			
		);					
		$arrResult = $objModel->mTLSPRun('mTL_TraingGetSingle',$arrParameter, 0,0);
		$urlPath = $objconfig->_setAttachFileUrlPath();
		$srcThumBnail = $this->getpathfile($urlPath, $arrResult['C_FILENAME_THUMB']);
		$attachFileThumbnail = $objFunction->FormAttachFileThumbnail($srcThumBnail,'TRAINING_DOC');
        $arrFileName = array();
	
		$arrResult['TD20'] = str_replace('!@!', ',', $arrResult['TD20']);
		$arrResult['TD10'] = str_replace('{', '', str_replace('}', '', $arrResult['TD10']));
		$arrResult['TD21TREE'] = '';
		$arrResult['TD24TREE'] = '';
		// ATTACH_FILE
		$filenamedocument = $arrResult['C_FILE_DOCUMENT'];
		$filenameflash = $arrResult['C_FILE_FLASH'];
		$hrefFileDocument = $this->getpathfile($urlPath, $filenamedocument);
		$hrefFileFlash = $this->getpathfile($urlPath, $filenameflash);
		$arrResult['C_FILE_DOCUMENT'] = $hrefFileDocument;
		$arrResult['C_FILE_FLASH'] = $hrefFileFlash;
		$attachFile = $objFunction->FormAttachDocument($filenamedocument,'TRAINING_DOC',$arrResult['TD01']);
		$attachFileFlash = $objFunction->FormAttachFlash($filenameflash,'TRAINING_DOC',$arrResult['TD01']);
		$arrResult['C_FILE_DOCUMENT_HTML'] = $attachFile;
		$arrResult['C_FILE_FLASH_HTML'] = $attachFileFlash;
        $arrResult['ATTACH_FILE_THUMB'] = $attachFileThumbnail;
        if($arrResult['TD21']){			
			$objXml = new Efy_Xml();
			$spRetHtml = $objXml->_generateHtmlForTreeUser($arrResult['TD21']) . '</div>';
			$arrResult['TD21TREE'] = $spRetHtml;
		}
		if($arrResult['FK_STAFF_DOWN_LIST']){			
			$objXml = new Efy_Xml();
			$spRetHtml = $objXml->_generateHtmlForTreeUser($arrResult['FK_STAFF_DOWN_LIST']) . '</div>';
			$arrResult['TD24TREE'] = $spRetHtml;
		}
		echo json_encode($arrResult);exit;		
	}
	public function delAction(){
		$objModel = new mtl_modTraining();		
		$objFunction = new Efy_Function_RecordFunctions();		
		$data = $this->_request->getParams('');						
		$arrParameter = array(	
			'td01' => isset($data['td01'])?$data['td01']:''			
		);					
		$arrResult = $objModel->mTLSPRun('mTL_TraingDelete',$arrParameter, 0,0);		
		echo json_encode($arrResult);exit;		
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 19/01/2012
	 * Y nghia: hien thi man hinh index UC - cap nhat y kien bai giang
	 */	
	public function commentAction(){
		$arrWards = array();
		$this->view->currentModulCodeForLeft = "comment";			
		$objFunction = New Efy_Function_RecordFunctions();
		$arrStaff = $_SESSION['arr_all_staff'];	
		$arrStaff = Efy_Publib_Library::_setColCode_Name($arrStaff,'true');
		$arrUnit  = $_SESSION['arr_all_unit'];	
		$this->view->titleBody = "DANH SÁCH BÀI GIẢNG CHỜ Ý KIẾN";					
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');	
		$this->view->arrListClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_LOP_HOC');
		$this->view->arrUnit = $arrUnit;
		$this->view->arrStaff = $arrStaff;
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 15;
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Lay du lieu man hinh hien thi nhung bai giang chua co y kien
	 */	
	public function indexcommentAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();		
		$data = $this->_request->getParams('');
		$staffId = $_SESSION['staff_id'];
		
		//Mảng lưu danh sách
		$arrResult = array();
		$dataSearch = $data['TD18'];
		$dataSearch = Efy_Publib_Library ::_Replace_VietNamese($dataSearch);
		$dataSearch = strtolower($dataSearch);
		$link_db_user  = $objconfig->_setDbLinkUser();
		$unit = $this->_request->getParam('UNIT');
		if ($unit == 'EF7FB156-516A-429E-9B3E-11109EA8D8DC')
			$unit = '';	
		//Mảng lưu tiêu chí tìm kiếm
		$arrParameter = array(	
			'TD03'                 => $this->_request->getParam('TD03'),
			'TDC02'                => $this->_request->getParam('TDC02'),
			'TD08'                 => $this->_request->getParam('TD08'),
			'TD09'                 => $this->_request->getParam('TD09'),
			'TD02'                 => $this->_request->getParam('TD02'),
			'UNIT'         		   => $unit,
			'TD04'         		   => $this->_request->getParam('TD04'),
			'TD18'         		   => $dataSearch,
			'TDSF05'         	   => $this->_request->getParam('C_STATUS'),
			'StaffID'			   => $staffId,
			'link_db_user'		   => $link_db_user,
			'iCurrentPage'         => $this->_request->getParam('hdn_current_page'),		
			'iNumberRecordPerPage' => $this->_request->getParam('hdn_record_number_page')				
		);
		$arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');		
		$arrResult = $objModel->mTLSPRun('mTL_TrainingCommentGetAll',$arrParameter, 1,0);		
		// var_dump($arrResult);
		for ($i=0; $i < sizeof($arrResult); $i++) { 			
			$arrResult[$i]['TD23'] = ($arrResult[$i]['TD23'] != null)?$arrResult[$i]['TD23']:'';
			$arrResult[$i]['TD19'] = ($arrResult[$i]['TD19'] != null)?str_replace('!@!', ', ', $arrResult[$i]['TD19']):'';
			$arrResult[$i]['TD06'] = Efy_Library::_getNameByCode($arrStatus,$arrResult[$i]['TD06'],'C_NAME');
			$sCreater = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$arrResult[$i]['TD04'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$arrResult[$i]['TD04'],'name');		
			$arrResult[$i]['TD17'] = $sCreater.': '.$arrResult[$i]['TD17']; 
			//Lay file dinh kem
			$strFileName 				= $arrResult[$i]['TD23'];									
			if($strFileName){				
				$sFile 						= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
				$arrResult[$i]['TD02']	.= $sFile;
			}

		}
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 			
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: hien thi man hinh index cac bai giang da co y kien
	 */	
	public function commentedAction(){
		$arrWards = array();		
		$objFunction = New Efy_Function_RecordFunctions();
		$arrStaff = $_SESSION['arr_all_staff'];	
		$arrStaff = Efy_Publib_Library ::_setColCode_Name($arrStaff,'true');
		$arrUnit  = $_SESSION['arr_all_unit'];	
		$this->view->titleBody = "DANH SÁCH BÀI GIẢNG ĐÃ CÓ Ý KIẾN";					
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');	
		$this->view->arrListClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_LOP_HOC');
		$this->view->arrUnit = $arrUnit;
		$this->view->arrStaff = $arrStaff;
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 15;	
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Lay du lieu man hinh hien thi chi tiet mot bai giang 
	 */	
	public function updatecommentAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$this->view->titleBody = 'Thông tin bài giảng';
		$this->view->titleBody1 = 'Nội dung ý kiến';
		$this->view->titleBody2 = 'Ý kiến liên quan';
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();
		$attachFile = $objFunction->FormAttachFile(array(),'TRAINING_COMMNET');
		$this->view->attachFile = $attachFile;
		$arrParameter = array(
			'TDSF01' => $this->_request->getParam('TDSF01',''));
		$arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');
		$arrResult = $objModel->mTLSPRun('mTL_TraningCommentGetSigle',$arrParameter, 0,0);
		$arrResult['TD23'] = ($arrResult['TD23'] != null)?$arrResult['TD23']:'';
		$arrResult['TD19'] = ($arrResult['TD19'] != null)?str_replace('!@!', ', ', $arrResult['TD19']):'';
		$arrResult['TD06'] = Efy_Library::_getNameByCode($arrStatus,$arrResult['TD06'],'C_NAME');
		$sFile = '';
		//Lay file dinh kem cua bai giang
		$strFileName 	= $arrResult['TD23'];
		if($strFileName){				
			$sFile 		= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
			$sFile         	= substr($sFile, 6);
		}
		$this->view->sFile = $sFile;
		$this->view->arrResult = $arrResult;
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Luu y kien nhan xet
	 */	
	public function savecommentAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$objconfig = new Efy_Init_Config();	
		$TCSP02 = $this->_request->getParam('TDSF01',null);
		$TCSP01 = $this->_request->getParam('TCSP01',null);
		$TCSP03 = $this->_request->getParam('TCSP03',null);
		$sContent = $this->_request->getParam('sContent',null);
		// $sContent = Efy_Publib_Library ::_replaceBadChar($sContent);
		$sStaffName = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
		$sStaffId = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'id');
		$arrParameter = array(
			'TCSP01'				=> $TCSP01,   // TCSP01 <> '' truong hop sua y kien.
			'TCSP02'				=> $TCSP02,
			'TCSP03'				=> $TCSP03,
			'TCSP04'				=> $sContent,
			'sStaffId'				=> $sStaffId,
			);
		$arrResult = $objModel->mTLSPRun('mTL_TraningCommentUpdate',$arrParameter, 0,0);
		//Upload file đính kèm		
		$sUrlFileAttach = $objconfig->_setAttachFileUrlPath();
		$hdn_UrlattachfileList = $this->_request->getParam('hdn_UrlattachfileList',null);
		$urlUncheckattachfileList = $this->_request->getParam('urlUncheckattachfileList',null);
		$recordId = $arrResult['NEW_ID'];				
		$fileNameAttachList = '';
		if($hdn_UrlattachfileList !='')
			$fileNameAttachList = $objFunction->_uploadFileAttachList($hdn_UrlattachfileList,$sUrlFileAttach);			
		$updateFile = $objFunction->UpdateFileInDB('T_mTL_TRAINING_COMMENT_STAFF_PROCESS', 'PK_TRAINING_COMMENT_STAFF_PROCESS', $recordId, 'TRAINING_COMMENT', $fileNameAttachList);
		//Xoa file
		if($urlUncheckattachfileList !=''){
			$arrDeleteFileList = explode('!~~!', $urlUncheckattachfileList);
			foreach ($arrDeleteFileList as $key => $value) {
				$file = '..'.$value;
				if(file_exists($file))
					unlink($file);			
			}
		}
		$this->getHelper('viewRenderer')->setNoRender(); 

	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: sua mot y kien nhan xet 
	 */	
	public function editcmmtedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$TCSP01 = $this->_request->getParam('TCSP01',null);
		$staffId = $_SESSION['staff_id'];		
		$arrParameter = array('TCSP01'			=>$TCSP01
								,'TCSP02'		=> ''
								,'staffId' 		=> $staffId
								,'TD01'			=>'');
		$arrResult = $objModel->mTLSPRun('mTL_TrainingCommentedGetAll',$arrParameter, 0,0);			
		$arrFileName = array();
		if($arrResult['TCSP05'])
			$arrFileName = explode('!~~!', $arrResult['TCSP05']);		
		$attachFile = $objFunction->FormAttachFile($arrFileName,'TRAINING_COMMENT',$arrResult['TCSP01']);
		$arrResult['TCSP05'] = $attachFile;
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 
	}
		/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Load cac y kien nhan xet 
	 */	
	public function loadcommentedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$TCSP01 = $this->_request->getParam('TCSP01',null);
		$TCSP02 = $this->_request->getParam('TCSP02',null);
		$TD01 = $this->_request->getParam('TD01',null);
		$staffId = $_SESSION['staff_id'];		
		$arrParameter = array('TCSP01'			=>$TCSP01
								,'TCSP02'		=> $TCSP02
								,'staffId' 		=> $staffId
								,'TD01'			=> $TD01);
		$arrResult = $objModel->mTLSPRun('mTL_TrainingCommentedGetAll',$arrParameter, 1,0);
		for ($i=0; $i < sizeof($arrResult); $i++) { 			
			$arrResult[$i]['TCSP05'] = ($arrResult[$i]['TCSP05'] != null)?$arrResult[$i]['TCSP05']:'';
			//Lay file dinh kem
			$strFileName 				= $arrResult[$i]['TCSP05'];									
			if($strFileName){				
				$sFile 						= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
				$arrResult[$i]['TCSP04']	.= $sFile;
			}

		}
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Xoa cac y kien nhan xet 
	 */	
	public function deletecmmtedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$arrParameter = array('TCSP01s' 			=> $this->_request->getParam('TCSP01s',null)
							,'delimitorElement'		=> $this->_request->getParam('delimitorElement',null));  
		$arrResult = $objModel->mTLSPRun('mTL_TrainingCommentDelete',$arrParameter, 0,0);
		var_dump($arrResult);
		$this->getHelper('viewRenderer')->setNoRender();
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: hien thi man hinh index UC - cap nhat y kien phe duyet
	 */	
	public function approveAction(){
		$this->auth();
		$arrWards = array();		
		$objFunction = New Efy_Function_RecordFunctions();
		$arrStaff = $_SESSION['arr_all_staff'];	
		$arrStaff = Efy_Publib_Library ::_setColCode_Name($arrStaff,'true');
		$arrUnit  = $_SESSION['arr_all_unit'];	
		$this->view->titleBody = "DANH SÁCH BÀI GIẢNG CHỜ DUYỆT";					
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');	
		$this->view->arrListClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_LOP_HOC');
		$this->view->arrUnit = $arrUnit;
		$this->view->arrStaff = $arrStaff;
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 15;	
	}
	public function approvedAction(){
		$this->auth();
		$arrWards = array();		
		$objFunction = New Efy_Function_RecordFunctions();
		$arrStaff = $_SESSION['arr_all_staff'];	
		$arrStaff = Efy_Publib_Library ::_setColCode_Name($arrStaff,'true');
		$arrUnit  = $_SESSION['arr_all_unit'];	
		$this->view->titleBody = "DANH SÁCH BÀI GIẢNG ĐÃ DUYỆT";					
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');	
		$this->view->arrListClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_LOP_HOC');
		$this->view->arrUnit = $arrUnit;
		$this->view->arrStaff = $arrStaff;
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 15;	
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Lấy danh sách can bo theo phong ban tuong ung
	 */	
	function groupstaffAction(){
		$objFunction = New Efy_Function_RecordFunctions();	
		$arrRecordType = Efy_Function_RecordFunctions::getRecordTypeByCurrentStaff(1,$_SESSION['OWNER_CODE']);	
		$arrStaff = $_SESSION['arr_all_staff'];	
		$result = array();
		$UNIT = $this->_request->getParam('UNIT','');
		// echo $UNIT;
		foreach ($arrStaff as $key => $value) {
			if($value['unit_id'] == $UNIT)
				$result[] = $arrStaff[$key];
		}
		$htmls ='<option value="" selected="selected">---Chọn cán bộ---</option>';
		if ($UNIT == '' || $UNIT == 'EF7FB156-516A-429E-9B3E-11109EA8D8DC' || $UNIT == '502AE491-1C3C-4FE4-99D1-C6CEC676F64B'){
			$result = $arrStaff;
		}
		$result = Efy_Publib_Library ::_setColCode_Name($result,'true');
		
		$htmls .=Efy_Library::_generateSelectOption($result,'id','id','name','');
		echo $htmls;
		die();
	}


/**
 * Nguoi tao: tuanpm
 * Ngay tao: 
 * Y nghia: Lay du lieu man hinh hien thi nhung bai giang chua co y kien phe duyet
 */	
	public function indexapproveAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();		
		$data = $this->_request->getParams('');
		$staffId = $_SESSION['staff_id'];		
		//Mảng lưu danh sách
		$arrResult = array();
		$dataSearch = $data['TD18'];
		$dataSearch = Efy_Publib_Library ::_Replace_VietNamese($dataSearch);
		$dataSearch = strtolower($dataSearch);
		$link_db_user  = $objconfig->_setDbLinkUser();
		$unit = $this->_request->getParam('UNIT');
		if ($unit == 'EF7FB156-516A-429E-9B3E-11109EA8D8DC')
			$unit = '';
		//Mảng lưu tiêu chí tìm kiếm
		$arrParameter = array(	
			'TD03'                 => $this->_request->getParam('TD03'),	
			'TDC02'                => $this->_request->getParam('TDC02'),
			'TD08'                 => $this->_request->getParam('TD08'),
			'TD09'                 => $this->_request->getParam('TD09'),
			'TD02'                 => $this->_request->getParam('TD02'),
			'UNIT'         		   => $this->_request->getParam('UNIT'),
			'TD04'         		   => $this->_request->getParam('TD04'),
			'TD18'         		   => $dataSearch,
			'TD06'         	   	   => $this->_request->getParam('C_STATUS'),
			'StaffID'			   => $staffId,
			'link_db_user'		   => $link_db_user,
			'iCurrentPage'         => $this->_request->getParam('hdn_current_page'),		
			'iNumberRecordPerPage' => $this->_request->getParam('hdn_record_number_page')				
		);
		$arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');		
		$arrResult = $objModel->mTLSPRun('mTL_TrainingApproveGetAll',$arrParameter, 1,0);		
		for ($i=0; $i < sizeof($arrResult); $i++) { 			
			$arrResult[$i]['TD23'] = ($arrResult[$i]['TD23'] != null)?$arrResult[$i]['TD23']:'';
			$arrResult[$i]['TD19'] = ($arrResult[$i]['TD19'] != null)?str_replace('!@!', ', ', $arrResult[$i]['TD19']):'';
			$arrResult[$i]['TD06'] = Efy_Library::_getNameByCode($arrStatus,$arrResult[$i]['TD06'],'C_NAME');
			$sCreater = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$arrResult[$i]['TD04'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$arrResult[$i]['TD04'],'name');		
			$arrResult[$i]['TD17'] = $sCreater.': '.$arrResult[$i]['TD17']; 
			//Lay file dinh kem
			$strFileName 				= $arrResult[$i]['TD23'];									
			if($strFileName){				
				$sFile 						= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
				$arrResult[$i]['TD02']	.= $sFile;
			}
		}
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 			
	}
	/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Lay du lieu man hinh hien thi chi tiet mot y kien phe duyet 
	 */	
	public function updateapproveAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$this->view->titleBody = 'Thông tin bài giảng';
		$this->view->titleBody1 = 'Nội dung phê duyệt';
		$this->view->titleBody2 = 'Nhật ký phê duyệt';
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();
		$LeaderName = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
		$attachFile = $objFunction->FormAttachFile(array(),'TRAINING_APPROVE');
		$this->view->attachFile = $attachFile;
		$arrParameter = array(
			'TD01' => $this->_request->getParam('TD01',''));
		$arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');
		$arrResult = $objModel->mTLSPRun('mTL_TraningApproveGetSigle',$arrParameter, 0,0);
		$arrResult['TD23'] = ($arrResult['TD23'] != null)?$arrResult['TD23']:'';
		$arrResult['TD19'] = ($arrResult['TD19'] != null)?str_replace('!@!', ', ', $arrResult['TD19']):'';
		$arrResult['TD06'] = Efy_Library::_getNameByCode($arrStatus,$arrResult['TD06'],'C_NAME');
		$sFile = '';
		//Lay file dinh kem cua bai giang
		$strFileName 	= $arrResult['TD23'];
		if($strFileName){				
			$sFile 		= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
			$sFile         	= substr($sFile, 6);
		}
		$this->view->sFile = $sFile;
		$this->view->LeaderName = $LeaderName;
		$this->view->arrResult = $arrResult;
	}
	
		/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Luu y kien phe duyet
	 */	
	public function saveapproveAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$objconfig = new Efy_Init_Config();	
		$TIL01 = $this->_request->getParam('TIL01',null);
		$TIL02 = $this->_request->getParam('TD01',null);
		$TIL04 = $this->_request->getParam('TIL04',null);
		$sContent = $this->_request->getParam('sContent',null);
		$TIL07 = $this->_request->getParam('TIL07',null);
		// $sContent = Efy_Publib_Library ::_replaceBadChar($sContent);
		$sStaffName = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code'). ' - '.Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
		$sStaffId = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'id');
		$arrParameter = array(
			'TIL01'					=> $TIL01,   // TIL01 <> '' truong hop sua y kien.
			'TIL02'					=> $TIL02,
			'TIL03'					=> $sStaffId,
			'TIL04'					=> $TIL04,
			'TIL05'					=> $sContent,
			'TIL07'					=> $TIL07,
			);
		$arrResult = $objModel->mTLSPRun('mTL_TrainingApprovedUpdate',$arrParameter, 0,0);
		//Upload file đính kèm		
		$sUrlFileAttach = $objconfig->_setAttachFileUrlPath();
		$hdn_UrlattachfileList = $this->_request->getParam('hdn_UrlattachfileList',null);
		$urlUncheckattachfileList = $this->_request->getParam('urlUncheckattachfileList',null);
		$recordId = $arrResult['NEW_ID'];	
		$fileNameAttachList = '';
		if($hdn_UrlattachfileList !='')
			$fileNameAttachList = $objFunction->_uploadFileAttachList($hdn_UrlattachfileList,$sUrlFileAttach);			
		$updateFile = $objFunction->UpdateFileInDB('T_mTL_TRAINING_IDEA_LEADER', 'PK_TRAINING_IDEA_LEADER', $recordId, 'TRAINING_APPROVE', $fileNameAttachList);
		//Xoa file
		if($urlUncheckattachfileList !=''){
			$arrDeleteFileList = explode('!~~!', $urlUncheckattachfileList);
			foreach ($arrDeleteFileList as $key => $value) {
				$file = '..'.$value;
				if(file_exists($file))
					unlink($file);			
			}
		}
		var_dump($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 

	}
	
		/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Sua mot y kien phe duyet 
	 */	
	public function editapprovedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$TIL01 = $this->_request->getParam('TIL01',null);
		$staffId = $_SESSION['staff_id'];		
		$arrParameter = array('TIL01'			=>$TIL01
								,'TD01'			=> ''
								,'staffId' 		=> $staffId
								);
		$arrResult = $objModel->mTLSPRun('mTL_TrainingApprovedGetAll',$arrParameter, 0,0);			
		$arrFileName = array();
		if($arrResult['TIL06'])
			$arrFileName = explode('!~~!', $arrResult['TIL06']);		
		$attachFile = $objFunction->FormAttachFile($arrFileName,'TRAINING_APPROVE',$arrResult['TIL01']);
		$arrResult['TIL06'] = $attachFile;
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 
	}
	
		/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Load cac y kien phe duyet
	 */	
	public function loadapprovedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$TD01 = $this->_request->getParam('TD01',null);
		$staffId = $_SESSION['staff_id'];		
		$arrParameter = array(	'TIL01'			=>''
								,'TD01'			=>$TD01
								,'staffId' 		=> $staffId);
		$arrResult = $objModel->mTLSPRun('mTL_TrainingApprovedGetAll',$arrParameter, 1,0);
		for ($i=0; $i < sizeof($arrResult); $i++) { 			
			$arrResult[$i]['TD23'] = ($arrResult[$i]['TD23'] != null)?$arrResult[$i]['TD23']:'';
			$strFileName 				= $arrResult[$i]['TD23'];									
			if($strFileName){				
				$sFile 						= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
				$arrResult[$i]['TD17']	.= $sFile;
			}

		}
		echo Zend_Json::encode($arrResult);
		$this->getHelper('viewRenderer')->setNoRender(); 
	}
	
		/**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Xoa cac y kien phe duyet
	 */	
	public function delapprovedAction(){
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$arrParameter = array('TIL01s' 			=> $this->_request->getParam('TIL01s',null)
							,'delimitorElement'		=> $this->_request->getParam('delimitorElement',null));  
		$arrResult = $objModel->mTLSPRun('mTL_TrainingApprovedDelete',$arrParameter, 0,0);
		var_dump($arrResult);
		$this->getHelper('viewRenderer')->setNoRender();
	}

	
     public function showdiaryAction(){
		$arrWards = array();		
		$objFunction = New Efy_Function_RecordFunctions();
		$objModel = new mtl_modTraining();
		$arrStaff = $_SESSION['arr_all_staff'];	
		$arrStaff = Efy_Publib_Library ::_setColCode_Name($arrStaff,'true');
		$arrUnit  = $_SESSION['arr_all_unit'];
		$arrParameter = array('td01' => $this->_request->getParam('td01',null)); 
		$arrResult = $objModel->mTLSPRun('mTL_TraingGetSingle',$arrParameter, 0,0);	
		$this->view->titleBody = "NHẬT KÝ BÀI GIẢNG";					
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');	
		$this->view->arrListClass = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_LOP_HOC');
		$this->view->arrResult = $arrResult;
		$this->view->arrStaff = $arrStaff;
		$this->view->leftTree = $objFunction->genLeftTree();
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 15;	
	}
     public function indexdiaryAction(){
     	$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();		
		$objModel = new mtl_modTraining();
		$td01     = $this->_request->getParam('td01',null);
		$arrParameter = array('td01' => $td01);
		$arrResultApprove = $objModel->mTLSPRun('mTL_TraingDiaryApproveGetAll',$arrParameter, 1,1);	
		for ($i=0; $i < sizeof($arrResultApprove); $i++) { 			
			$arrResultApprove[$i]['TIL06'] = ($arrResultApprove[$i]['TIL06'] != null)?$arrResultApprove[$i]['TIL06']:'';
			$strFileName 				= $arrResultApprove[$i]['TIL06'];									
			if($strFileName){				
				$sFile 						= Efy_Library::_getAllFileAttach($strFileName,"!~~!","!~!",$this->view->baseUrl . "attach-file/");
				$arrResultApprove[$i]['TIL05']	.= $sFile;
			}
		}
		echo Zend_Json::encode($arrResultApprove);
		$this->getHelper('viewRenderer')->setNoRender(); 
     }
    /**
	 * Nguoi tao: Tuanpm
	 * Ngay tao: 19/03/2013
	 * Y nghia: Tong hop tinh hinh tao bai giang cua can bo
	 */	 
    public function synthesisAction(){
    	$this->authsynthesis();
    	$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();
    	$objModel = new mtl_modTraining();
    	$arrStaff = Efy_Publib_Library ::_setColCode_Name($_SESSION['arr_all_staff'],'true');
    	$this->view->titleBody = 'TỔNG HỢP TÌNH HÌNH XỬ LÝ BÀI GIẢNG';
    	$this->view->arrStatus = $objFunction->getAllObjectbyListCode($_SESSION['OWNER_CODE'],'DM_TRANG_THAI');						
		$this->view->arrListItem = $objFunction->getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');		
		$this->view->arrStaff = $arrStaff;
		$this->view->iCurrentPage = 1;
		$this->view->iNumberRecordPerPage = 100;	
    }
    public function indexsynthesisAction(){
    	$objFunction = New Efy_Function_RecordFunctions();
		$objconfig = new Efy_Init_Config();
    	$objModel = new mtl_modTraining();
    	$link_db_user  = $objconfig->_setDbLinkUser();
    	$status = $this->_request->getParam('status','');
    	$link_db_doc  = $objconfig->_setDbLinkDoc();
    	$kieuin = $this->_request->getParam('kieuin','');
    	$arrParameter = array(	
			'staffId'			   => $this->_request->getParam('staffId',''),
			'fromDate'			   => $this->_request->getParam('fromDate',''),	
			'toDate'			   => $this->_request->getParam('toDate',''),
			'ownerCode'            => $_SESSION['OWNER_CODE'],
			'status'			   => $status,	
			'dblinkuser'		   => $link_db_user,	
			'dblinkdoc'			   => $link_db_doc,
			'iCurrentPage'         => $this->_request->getParam('hdn_current_page'),		
			'iNumberRecordPerPage' => $this->_request->getParam('hdn_record_number_page'),				
		);
		$arrResult = $objModel->mTLSPRun('mTL_TraingSynthesis',$arrParameter, 1,0);
		if ($kieuin == 'excel'){
			$v_export_filename ='';
			$dirTemplate = './templates/BCTH/mau_giay_in.xls';
			$v_export_filename = $this->createreportexcel($dirTemplate,$arrResult);
			$my_report_file = 'http://'.$_SERVER['HTTP_HOST'].$this->_request->getBaseUrl() .'/public/export/' . $v_export_filename;
			echo $my_report_file;
			$this->getHelper('viewRenderer')->setNoRender();
		}
    	else {
    		echo Zend_Json::encode($arrResult);
			$this->getHelper('viewRenderer')->setNoRender();
		}
    }
	public function createreportexcel($dirTemplate,$data){

		Zend_Loader::loadClass('Efy_IOFactory');
		//Tao doi tuong
		$objReader = Efy_IOFactory::createReader('Excel5');
		$objPHPExcel = $objReader->load($dirTemplate);
		$objPHPExcel->setActiveSheetIndex(0);
		$objWorksheet = $objPHPExcel->getActiveSheet();	
		isset($data[0]['C_TOTAL_RECORD'])? $total_group = $data[0]['C_TOTAL_RECORD'] : $total_group = 0;
		$baseRow =6;
		$objWorksheet->insertNewRowBefore($baseRow,sizeof($data));
		if(is_array($data)){
			$count = 0;
			$default = '';
			$defaultName = '';
			$row = $baseRow;
			foreach($data as $r => $dataRow) {
				$count++;
				$objWorksheet->setCellValue('A'.$row, $count);
				$objWorksheet->setCellValue('B'.$row, $dataRow['C_NAME']);
				$objWorksheet->setCellValue('C'.$row, $dataRow['SEND_DOC_EXCEL']);
				$objWorksheet->setCellValue('D'.$row, $dataRow['RECEIVE_DOC_EXCEL']);
				$objWorksheet->setCellValue('E'.$row, $dataRow['TRAINING_DOC_EXCEL']);
				$objWorksheet->setCellValue('F'.$row, '');
				//Autofit
				$objWorksheet->getRowDimension($row)->setRowHeight(-1);
				$row++;
			}
	    }
	    $objWorksheet->setCellValue('E'.($row+2),'HIỆU TRƯỞNG');
	    $objWorksheet->mergeCells('E'.($row+2).':F'.($row+2));		
		$objWorksheet->setCellValue('E'.($row+4),'Đỗ Thị Nụ');
		$objWorksheet->mergeCells('E'.($row+4).':F'.($row+4));
		$objWorksheet->removeRow($baseRow-1,1);
		$fileName = "nv01".date('dmy').date('His');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$fileName = $fileName.".xls";
		// Duong dan file report
		$path = $_SERVER['SCRIPT_FILENAME'];
		$path = substr($path, 0, -9);
		$reportFile = str_replace("/", "\\", $path) . "public\\export\\" . $fileName;
		$objWriter->save($reportFile);
		return $fileName;
	}
}
?>
